package com.dps.metrics.config;

import com.dps.metrics.factory.GlobalMetricsFactory;
import com.dps.metrics.factory.MicrometerMetricsFactory;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;

public class FusionMetricsAutoConfiguration {

//    @Bean
//    public MetricsFactory metricsFactory(MeterRegistry meterRegistry) {
//        GlobalMetricsFactory.registered(new MicrometerMetricsFactory(meterRegistry));
//        return GlobalMetricsFactory.getGlobal();
//    }

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName, @Value("${spring.profiles.active}") String env) {
        return (registry) -> {
            registry.config().commonTags("application", applicationName, "env", env);
            GlobalMetricsFactory.registered(new MicrometerMetricsFactory(registry));
        };
    }
}
